import DebugUtils from "./utils/DebugUtils";

export default class SnakeCell extends cc.Component {
    static instance(skin?: cc.SpriteFrame): SnakeCell {
        let node = new cc.Node("snakeCell")
        node.addComponent(cc.Sprite)
        node.setAnchorPoint(0.5, 0.5)
        let snake = node.addComponent(SnakeCell)
        snake.setSkin(skin)
        return snake
    }

    public get tag(): number {
        return this.node.tag
    }

    public set tag(tag: number) {
        this.node.tag = tag
    }

    public get position(): cc.Vec2 {
        return this.node.position
    }

    public set position(pos: cc.Vec2) {
        this.node.position = pos
    }

    public set offset(offset: cc.Vec2) {
        this.node.position.addSelf(offset)
    }

    public setSkin(sprite: cc.SpriteFrame) {
        this.node.getComponent(cc.Sprite).spriteFrame = sprite
        if (sprite) {
            this.node.width = sprite.getRect().width
            this.node.height = sprite.getRect().height
        }
        DebugUtils.showBound(this.node, false)
    }
}